package com.itheima.youdianda.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.common.ResultData;
import com.itheima.youdianda.common.UserThread;
import com.itheima.youdianda.dto.ArticleDto;
import com.itheima.youdianda.entity.*;
import com.itheima.youdianda.service.*;
import com.itheima.youdianda.util.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/index")
@Slf4j
@CrossOrigin
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private YddCateService yddCateService;
    @Autowired
    private YddArticleService yddArticleService;
    @Autowired
    private YddAdvposService yddAdvposService;
    @Autowired
    private YddTagService yddTagService;
    @Autowired
    private YddAdvimgService yddAdvimgService;
    @Autowired
    private YddUserService yddUserService;
    @Autowired
    private YddLinkService yddLinkService;
    @Autowired
    private YddUserDataService yddUserDataService;

    @PostMapping("/login")
    public R login(@RequestBody SysUser sysUser){
        log.info("登陆用户：{}",sysUser.toString());

        String loginName = sysUser.getLoginName();
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getLoginName, loginName);
        SysUser one = sysUserService.getOne(wrapper);

        if (one == null){
            return R.error("账号不存在");
        }else if (one.getStatus() == 0){
            return R.error("账号已禁用");
        }

        String password = sysUser.getPassword();
        if (one.getPassword().equals(generatePassword(password))){
            //把用户id 加密进token里

            // 生成token信息
            Map retMap = new HashMap();
            Map tokenMap = new HashMap<>();
            String roleId = one.getRoleId()
                    .replace("[","")
                    .replace("]", "")
                    .replace("\"", "");

            tokenMap.put("userId", one.getId());
            tokenMap.put("roleId", roleId);

            String token = JwtUtils.getToken(tokenMap);
            retMap.put("token", token);
            return R.success("token", JwtUtils.getToken(tokenMap));
        }
        return R.error("密码错误");

    }



    @GetMapping("/getConfig")
    public R systemConfig(){
        LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysConfig::getTabValue,"system");
        List<SysConfig> sysConfigs = sysConfigService.list(wrapper);

        HashMap<String, String> map = new HashMap<>();
        for (SysConfig sysConfig : sysConfigs) {
            map.put(sysConfig.getAttrKey(),sysConfig.getAttrValue());
        }

        return new R(map,"",0);

    }

    @PostMapping("/profile")
    public R profile(HttpServletRequest request){
        String token = request.getHeader("x-token");

        Claims claims = JwtUtils.getClaims(token);
        Long userId = Long.valueOf((String) claims.get("userId"));

        log.info("用户id:{}",userId);
        return sysUserService.profile(userId);
    }

/** md5加密
     * @param password 密码*/


    private String generatePassword(String password){
        return DigestUtils.md5DigestAsHex(password.getBytes());
    }


    @GetMapping("/baseInfo")
    public R baseInfo(){
        HashMap<String,Object> map = new HashMap<>();
        //1. 查询 分类数据
        List<YddCate> yddCateList = yddCateService.list();
        List<YddCate> yddCates = yddCateList.stream().map(yddCate -> {
            Integer cateId = yddCate.getId();
            LambdaQueryWrapper<YddArticle> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(YddArticle::getCateid, cateId);
            int count = yddArticleService.count(queryWrapper);
            yddCate.setNum(count);
            return yddCate;
        }).collect(Collectors.toList());
        map.put("all_cate",yddCates);
        //2.查询广告位总数
        int count = yddAdvposService.count();
        map.put("advpos_num",count);
        //3.标签总数
        int tagCount = yddTagService.count();
        map.put("tag_num",tagCount);
        //4.管理员总数 admin_num
        int userCount = sysUserService.count();
        map.put("admin_num",userCount);
        //5.文章总数
        int articleCount = yddArticleService.count();
        map.put("article_num",articleCount);
        //6.分类总数
        int cateCount = yddCateService.count();
        map.put("cate_num",cateCount);
        //7.广告图总数
        int advimgCount = yddAdvimgService.count();
        map.put("advimg_num",advimgCount);
        //8.最新用户数据
        LambdaQueryWrapper<YddUser> yddUserQuery = new LambdaQueryWrapper<>();
        yddUserQuery.orderByDesc(YddUser::getId).last("limit 7");
        List<YddUser> yddUserList = yddUserService.list(yddUserQuery);
        map.put("new_user",yddUserList);
        //9.热门文章数据
        LambdaQueryWrapper<YddArticle> yddArticleQuery = new LambdaQueryWrapper<>();
        yddArticleQuery.orderByDesc(YddArticle::getLovenum).last("limit 7");
        List<YddArticle> yddArticles = yddArticleService.list(yddArticleQuery);
        map.put("hot_article",yddArticles);
        //10.用户数据
        Map<String,Integer> userMap = new HashMap();
        int totalCount = yddUserService.count();
        yddUserQuery = new LambdaQueryWrapper<>();
        yddUserQuery.eq(YddUser::getSex,0);  //男的数量
        int user_man = yddUserService.count(yddUserQuery);
        int user_women = totalCount - user_man;
        userMap.put("total",totalCount);
        userMap.put("user_man",user_man);
        userMap.put("user_woman",user_women);
        map.put("user",userMap);

        return new R(map,"",0);
    }






    //前台的
    //--------------------------------------------------------------------
    @GetMapping("/index")
    public ResultData index(){
        //0.返回的map
        Map allDataMap = new HashMap();
        //1.查询第一层allCate数据
        LambdaQueryWrapper<YddCate> cateLambdaQueryWrapper = new LambdaQueryWrapper<>();
        cateLambdaQueryWrapper.orderByAsc(YddCate::getSortNum);
        List<YddCate> yddCates = yddCateService.list(cateLambdaQueryWrapper);//1
        allDataMap.put("allCate",yddCates);

        //2.查询第二层config
        //1. 查询组件名称
        LambdaQueryWrapper<SysConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.groupBy(SysConfig::getTabValue);
        List<SysConfig> sysConfigs = sysConfigService.list(queryWrapper);
        List<String> tabValues = new ArrayList<>();
        List<String> tableValues = sysConfigs.stream().map(sysConfig -> {
            return sysConfig.getTabValue();
        }).collect(Collectors.toList());

        //2.根据组件名称查询子类数据
        List<SysConfig> list = sysConfigService.list();
        //3.创建三个空集合
        List<SysConfig> baseConfigs = new ArrayList<>();
        List<SysConfig> systemConfigs = new ArrayList<>();
        List<SysConfig> customConfigs = new ArrayList<>();
        for (SysConfig sysConfig : list) {
            if ("base".equals(sysConfig.getTabValue())) {
                baseConfigs.add(sysConfig);
            } else if ("system".equals(sysConfig.getTabValue())) {
                systemConfigs.add(sysConfig);
            } else {
                customConfigs.add(sysConfig);
            }
        }

        //4.将base集合按名称拆分成3个集合
        List<List<SysConfig>> baseConfigGroupList = new ArrayList<>();
        baseConfigs.stream().collect(Collectors.groupingBy(SysConfig::getGroupValue, Collectors.toList())).forEach((model, configList) -> {
            baseConfigGroupList.add(configList);
        });
        List baseChildrenList = new ArrayList();
        for (List<SysConfig> sysConfigList : baseConfigGroupList) {
            Map map = new HashMap();

            if (sysConfigList.get(0).getGroupValue().equals("站点配置")) {
                List list1 = new ArrayList();
                Map map1 = new HashMap();
                Map map2 = new HashMap();
                map1.put("label", "是");
                map1.put("value", "1");
                map2.put("label", "否");
                map2.put("value", "2");
                list1.add(map1);
                list1.add(map2);
                for (SysConfig sysConfig : sysConfigList) {
                    if (sysConfig.getAttrKey().equals("close_website")) {
                        sysConfig.setConfig_value(list1);
                        break;
                    }
                }

                map.put("name", "站点配置");
                map.put("data", sysConfigList);
                baseChildrenList.add(map);
            } else if (sysConfigList.get(0).getGroupValue().equals("底部信息")) {
                map.put("name", "底部信息");
                map.put("data", sysConfigList);
                baseChildrenList.add(map);
            } else {
                map.put("name", "其他配置");
                map.put("data", sysConfigList);
                baseChildrenList.add(map);

            }
        }

        List list1 = new ArrayList();
        list1.add(baseChildrenList.get(1));
        list1.add(baseChildrenList.get(2));
        list1.add(baseChildrenList.get(0));


        //4.将system集合按名称拆分成集合
        List systemChildrenList = new ArrayList();
        Map map = new HashMap();
        map.put("name", systemConfigs.get(0).getGroupValue());
        map.put("data", systemConfigs);
        systemChildrenList.add(map);

        //5.将custom集合拆分
        List<List<SysConfig>> customConfigGroupList = new ArrayList<>();
        customConfigs.stream().collect(Collectors.groupingBy(SysConfig::getGroupValue, Collectors.toList())).forEach((model, configList) -> {
            customConfigGroupList.add(configList);
        });

        List customChildrenList = new ArrayList();
        for (List<SysConfig> sysConfigList : customConfigGroupList) {
            Map map1 = new HashMap();
            if (sysConfigList.get(0).getGroupValue().equals("前台图片")) {
                map1.put("name", "前台图片");
                map1.put("data", sysConfigList);
                customChildrenList.add(map1);
            } else if (sysConfigList.get(0).getGroupValue().equals("通知公告")) {
                map1.put("name", "通知公告");
                map1.put("data", sysConfigList);
                customChildrenList.add(map1);
            }
        }

        //6.
        Map baseMap = new HashMap();
        Map systemMap = new HashMap();
        Map customMap = new HashMap();

        baseMap.put("name", "基础配置");
        baseMap.put("key", "base");
        baseMap.put("children", list1);

        systemMap.put("name", "系统设置");
        systemMap.put("key", "system");
        systemMap.put("children", systemChildrenList);

        customMap.put("name", "其他设置");
        customMap.put("key", "custom");
        customMap.put("children", customChildrenList);

        //7.
        List firstList = new ArrayList();
        firstList.add(baseMap);
        firstList.add(systemMap);
        firstList.add(customMap);

        //8.创建最大的map
        Map returnMap = new HashMap();   // 2
        returnMap.put("list", firstList);


        //9.查询所有数据allData
        QueryWrapper<SysConfig> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.select("id", "attr_key", "attr_value", "validator", "config_value", "type");
        List<SysConfig> sysConfigList = sysConfigService.list(configQueryWrapper);
        for (SysConfig sysConfig : sysConfigList) {
            if (StringUtils.isNotEmpty(sysConfig.getConfigValue())) {
                log.info(sysConfig.getConfigValue());
                String configValue = sysConfig.getConfigValue();
                String[] split = configValue.split("&");
                List<Map> configVal = new ArrayList<>();
                for (String s : split) {
                    Map map1 = new HashMap();
                    String[] split1 = s.split("=");
                    map1.put("label", split1[0]);
                    map1.put("value", split1[1]);
                    configVal.add(map1);
                }

                sysConfig.setConfig_value(configVal);
            }
        }
        returnMap.put("allData", sysConfigList);

        allDataMap.put("config",returnMap);

        //3.查询第三层allTag
        List<YddTag> yddTags = yddTagService.list();  // 3
        allDataMap.put("allTag",yddTags);

        //4.查询第四层allLink
        List<YddLink> yddLinks = yddLinkService.list();
        allDataMap.put("allLink",yddLinks);

        //5.查询第五层banner  轮播图
        LambdaQueryWrapper<YddAdvimg> yddAdvimgLambdaQueryWrapper = new LambdaQueryWrapper<>();
        yddAdvimgLambdaQueryWrapper.eq(YddAdvimg::getAdvimgpos,15);
        List<YddAdvimg> yddAdvimgs = yddAdvimgService.list(yddAdvimgLambdaQueryWrapper);
        allDataMap.put("banner",yddAdvimgs);

        //6.查询第六层sideBanner 侧边栏图片
        yddAdvimgLambdaQueryWrapper = new LambdaQueryWrapper<>();
        yddAdvimgLambdaQueryWrapper.eq(YddAdvimg::getAdvimgpos,14);
        List<YddAdvimg> yddAdvimgs1 = yddAdvimgService.list(yddAdvimgLambdaQueryWrapper);
        allDataMap.put("sideBanner",yddAdvimgs1);

        //7.查询第7层showBanner 详情
        yddAdvimgLambdaQueryWrapper = new LambdaQueryWrapper<>();
        yddAdvimgLambdaQueryWrapper.eq(YddAdvimg::getAdvimgpos,13);
        List<YddAdvimg> yddAdvimgs2 = yddAdvimgService.list(yddAdvimgLambdaQueryWrapper);
        allDataMap.put("showBanner",yddAdvimgs2);
        return ResultData.ok("成功",allDataMap);
    }


    @GetMapping("/new")
    public R page(Integer page,Integer limit){
        Page<YddArticle> yddArticlePage = new Page<>(page, limit);
        LambdaQueryWrapper<YddArticle> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(YddArticle::getCreateDate);
        yddArticleService.page(yddArticlePage,lqw);
        //Page<ArticleDto> articleDtoPage = new Page<>();
        //BeanUtils.copyProperties(yddArticlePage,articleDtoPage,"records");

        List<YddArticle> records = yddArticlePage.getRecords();
        List<ArticleDto> list = new ArrayList<>();
        for (YddArticle yddArticle : records) {

            String catename = yddCateService.getById(yddArticle.getCateid()).getCatename();
            ArticleDto articleDto = new ArticleDto();
            BeanUtils.copyProperties(yddArticle,articleDto);
            articleDto.setCatename(catename);
            list.add(articleDto);
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count",yddArticlePage.getTotal());
        map.put("totalPages",yddArticlePage.getPages());
        map.put("pageSize",yddArticlePage.getSize());
        map.put("currentPage",yddArticlePage.getCurrent());
        map.put("data",list);
        R r = R.success("desc", "首页大列表");
        r.putData("num_day",132);
        r.putData("num_week",135);
        r.putData("list",map);
        return r;
    }

    @GetMapping("/list")
    public ResultData list(int page,int limit,Integer cateid){
        log.info("传来的数据为:{}{}{}",page,limit,cateid);
        //创建分页查询构造器
        Page<YddArticle> pageInfo = new Page<>(page,limit);
        Page<ArticleDto> articleDtoPage = new Page<>();
        //创建构造器
        LambdaQueryWrapper<YddArticle> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(cateid.toString()),YddArticle::getCateid,cateid);
        lambdaQueryWrapper.orderByDesc(YddArticle::getCreateDate);
        Page<YddArticle> yddArticlePage = yddArticleService.page(pageInfo, lambdaQueryWrapper);

        //对象的拷贝
        BeanUtils.copyProperties(yddArticlePage,articleDtoPage,"records");
        //获取查询出出来的数据
        List<YddArticle> records = yddArticlePage.getRecords();
        //创建一个新的集合来存放添加后的数据
        List<ArticleDto> yddArticleDtos = new ArrayList<>();
        //对records进行遍历
        for (YddArticle record : records) {
            ArticleDto yddArticleDto = new ArticleDto();
            //拷贝数据到Dto中
            BeanUtils.copyProperties(record,yddArticleDto);
            //获取分类id
            Integer cateid1 = record.getCateid();
            //调用分类业务代码执行业务
            YddCate cate = yddCateService.getById(cateid1);
            yddArticleDto.setCatename(cate.getCatename());
            yddArticleDtos.add(yddArticleDto);
        }
        //将数据添加到articleDtoPage分页器中
        articleDtoPage.setRecords(yddArticleDtos);
        //定义一个pageBean的返回对象
        PageBean<ArticleDto> pageBean = new PageBean<>();
        pageBean.setCount((int)articleDtoPage.getTotal());
        pageBean.setCurrentPage((int)articleDtoPage.getCurrent());
        pageBean.setPageSize((int)articleDtoPage.getSize());
        pageBean.setTotalPages((int)articleDtoPage.getPages());
        pageBean.setData(articleDtoPage.getRecords());
        //创建一个list集合

        Map map = new HashMap();
        map.put("list",pageBean);
        return ResultData.ok("查询成功",map);
    }


    @GetMapping("/hot")
    public ResultData hot(){
        LambdaQueryWrapper<YddArticle> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(YddArticle::getLovenum);
        queryWrapper.last("limit 0, 6");
        List<YddArticle> yddArticleList = yddArticleService.list(queryWrapper);

        List<Integer> cateIds = yddArticleList.stream().map(yddArticle -> {
            return yddArticle.getCateid();
        }).collect(Collectors.toList());

        List<YddCate> yddCateList = yddCateService.listByIds(cateIds);

        List<ArticleDto> articleList = yddArticleList.stream().map(yddArticle -> {
            ArticleDto articleDto = new ArticleDto();
            BeanUtils.copyProperties(yddArticle,articleDto);
            for (YddCate yddCate : yddCateList) {
                articleDto.setCatename(yddCate.getCatename());
            }
            return articleDto;
        }).collect(Collectors.toList());
        Map map = new HashMap();
        map.put("desc","侧边最新文章");
        map.put("list",articleList);
        return ResultData.ok("成功",map);
    }

    @GetMapping("show")
    public R show(Integer id) {
        ArticleDto info = new ArticleDto();
        YddArticle yddArticle = yddArticleService.getById(id);
        BeanUtils.copyProperties(yddArticle, info);
        String catename = yddCateService.getById(yddArticle.getCateid()).getCatename();
        info.setCatename(catename);

        LambdaQueryWrapper<YddArticle> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(YddArticle::getId);
        List<YddArticle> list = yddArticleService.list(wrapper);
        HashMap<String, Object> prev = new HashMap<>();
        HashMap<String, Object> next = new HashMap<>();
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            if (id == list.get(i).getId()) {
                count = i;
            }
        }

        if (count != 0 && list.get(count - 1) != null) {
            prev.put("id", list.get(count - 1).getId());
            prev.put("title", list.get(count - 1).getTitle());
        }

        if (count != list.size() - 1 && list.get(count + 1) != null) {
            next.put("id", list.get(count + 1).getId());
            next.put("title", list.get(count + 1).getTitle());
        }

        LambdaQueryWrapper<YddArticle> lqw = new LambdaQueryWrapper<>();
        lqw.eq(YddArticle::getCateid, yddArticle.getCateid());
        lqw.last("limit 8");
        List<YddArticle> recommend = yddArticleService.list(lqw);
        int num = -1;
        for (int i = 0; i < recommend.size(); i++) {
            if (recommend.get(i).getId() == id) {
                num = i;
                break;
            }
        }
        if (num != -1) {
            recommend.remove(num);
        }

        R r = R.success("prev", Collections.singleton(prev));
        r.putData("next", Collections.singleton(next));
        r.putData("info", info);
        r.putData("recommend", recommend);
        return r;
    }


    @GetMapping("/myArticle")
    public ResultData myArticle(int page,int limit){
        log.info("传过来的数据为:{}{}",page,limit);
        String userId = UserThread.getUserId();
        //构建分页构造器
        Page<YddArticle> yddArticlePage = new Page<>(page,limit);
        LambdaQueryWrapper<YddArticle> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(userId),YddArticle::getUserId,userId);
        lambdaQueryWrapper.orderByDesc(YddArticle::getCreateDate);
        Page<YddArticle> page1 = yddArticleService.page(yddArticlePage, lambdaQueryWrapper);
        //封装插查询的数据
        PageBean<YddArticle> pageBean = new PageBean<>();
        pageBean.setCount((int)page1.getTotal());
        pageBean.setCurrentPage((int)page1.getCurrent());
        pageBean.setPageSize((int)page1.getSize());
        pageBean.setTotalPages((int)page1.getPages());
        pageBean.setData(page1.getRecords());
        return ResultData.ok("查询成功",pageBean);
    }


/*****
     * 侧边文章查询
     * @return*/


    @GetMapping("/recommend")
    public ResultData recomend(){
        LambdaQueryWrapper<YddArticle> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(YddArticle::getLovenum);
        queryWrapper.last("limit 0, 6");
        List<YddArticle> yddArticleList = yddArticleService.list(queryWrapper);

        List<Integer> cateIds = yddArticleList.stream().map(yddArticle -> {
            return yddArticle.getCateid();
        }).collect(Collectors.toList());

        List<YddCate> yddCateList = yddCateService.listByIds(cateIds);

        List<ArticleDto> articleList = yddArticleList.stream().map(yddArticle -> {
            ArticleDto articleDto = new ArticleDto();
            BeanUtils.copyProperties(yddArticle,articleDto);
            for (YddCate yddCate : yddCateList) {
                articleDto.setCatename(yddCate.getCatename());
            }
            return articleDto;
        }).collect(Collectors.toList());
        Map map = new HashMap();
        map.put("desc","侧边推荐文章");
        map.put("list",articleList);
        return ResultData.ok("成功",map);
    }



     /**
     * 前端-注册
     * @param yddUser
     * @return
      */


    @PostMapping("/reg")
    public ResultData reg(@RequestBody YddUser yddUser) {
        //手机号唯一性判断
        String mobile = yddUser.getMobile();
        LambdaQueryWrapper<YddUser> yddUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        yddUserLambdaQueryWrapper.eq(YddUser::getMobile,mobile);
        List<YddUser> list = yddUserService.list(yddUserLambdaQueryWrapper);
        if (list.size()!=0){
            return ResultData.error("手机号已存在");
        }
        //对密码进行加密
        String password = yddUser.getPassword();
        String md5Password = generatePassword(password);
        //对加密后的数据进行处理

        YddUser user = new YddUser();
        user.setPassword(md5Password);
        user.setMobile(yddUser.getMobile());
        user.setUsername(yddUser.getMobile());


        //进行用户存储(插入之后需要返回主键)
        yddUserService.save(user);
        Integer id = user.getId();

        LambdaQueryWrapper<YddUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YddUser::getId, id);
        //获取存取之后的数据--userInfo
        YddUser one = yddUserService.getOne(wrapper);
        //获取发布的文章数量--articleNum
        LambdaQueryWrapper<YddUserData> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(YddUserData::getUserId, one.getId());
        int articleCount = yddUserDataService.count(queryWrapper);
        //获取点赞数量 type=2
        int num1 = count(2,id);
        //收藏数量  type=1
        int num2 = count(1,id);

        //进行组装返回
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("userInfo", one);
        hashMap.put("articleNum", articleCount);
        hashMap.put("zanNum", num1);
        hashMap.put("collectNum", num2);

        //返回成功标志
        return ResultData.ok("", hashMap);

    }



/*
*
     * 点赞收藏的数量统计
     * @param type
     * @return
*/


    public int count(int type,int id) {
        LambdaQueryWrapper<YddUserData> yddUserDataLambdaQueryWrapper = new LambdaQueryWrapper<>();
        yddUserDataLambdaQueryWrapper.eq(YddUserData::getType, type);
        yddUserDataLambdaQueryWrapper.eq(YddUserData::getUserId,id);
        int num = yddUserDataService.count(yddUserDataLambdaQueryWrapper);
        return num;
    }


}
